package edu.gatech.oad.antlab.person;
/**
 *  A simple class for person 3
 *  returns their name and a
 *  reversed string 
 *  
 *  @author  Nick
 *  @version 1.1
 */
public class Person3 {
   /** Holds the persons real name */  
	private String name;
	
	/**
	 * The constructor, takes in the persons
	 * name
	 * @param pname the person's real name
	 */
	public Person3(String pname){
	  name = pname;
	}
	
	/**
	 * Return a string rep of this object
	 * that varies with an input string
	 *
	 * @param input the varying string
	 * @return the string representing the 
	 *         object
	 */
	public String toString(String input) {
	  return name + calc(input);
	}
	
	/**
	 * This method should take the string
	 * input and return its reverse.
	 * given "gtg123b" it should return
	 * b321gtg.
	 *
	 * @param input the string to be reversed
	 * @return the reversed string
	 */
	private String calc(String input) {
	  //Person 3 put your implementation here
		String[] inOrder = new String[input.length()];
		for(int i = 0; i < inOrder.length; i++){
			String a = input.substring(i, i + 1);
			inOrder[i] = a;
		}
		//prints out the array, for reference
		for(String i:inOrder){
			System.out.print(i + " ");
		}
		System.out.println("");
		
		//reverse the string 
		String[] reversed = new String[inOrder.length];
		// take the elements from the back of the inOrder array and put them at the front of the reversed array
		int j = 0; // the index to put the elements at in reversed array
		for(int i = inOrder.length - 1; i >= 0; i--){
			reversed[j] = inOrder[i];
			j++;
		}
		//Shows the user if the array was reversed
		for(String i:reversed){
			System.out.print(i + " ");
		}
		System.out.println("");
		//put the elements from reversed into one string
		String inputReversed = "";
		for(String i: reversed){
			inputReversed += i;
		}
	  return inputReversed;
	}
	
	/**
	 * This main method runs tests of the toString method, which indirectly tests the calc method 
	 * @param args
	 */
	public static void main(String[] args){
		Person3 me = new Person3("Nick");
		System.out.println(me.toString("racecar"));
		System.out.println(me.toString("kciN"));
		System.out.println(me.toString("--n"));
	}
}